//
// Created by DengLibin on 2018/12/12 0012.
//
/**
 * 函数模版和类模版
 * 模板函数会严格按照数据类型匹配,不会发生隐式转换
 */
#include <iostream>
using namespace std;

//交换 函数模板
template <typename T>
void my_swap(T &t1, T &t2)
{
    T temp;
    temp = t1;
    t1 = t2;
    t2 = temp;
}
void test1()
{
    int a = 10;
    int b = 20;
    my_swap<int>(a, b);
    cout << "a = " << a << " ,b = " << b << endl;
    double x = 10.23;
    double  y = 20.2324;
    my_swap<double >(x, y);
    cout << "x = " << x << " ,y = " << y << endl;
}

//类模板
template <typename  T>
class TemplateUser
{
private:
    T t;
public:
    TemplateUser(T t)
    {
        cout <<"TemplateUser构造函数"<<endl;
        this->t = t;
    }
    void print()
    {
        cout << this->t<<endl;
    }
};
void test2()
{
    TemplateUser<int> user(23);
    user.print();
}
//继承类模版
class ChildUser:public TemplateUser<double >
{
public:
    ChildUser(double age):TemplateUser(age)
    {
        cout <<"ChildUser构造函数"<<endl;
    }
};

void test3()
{
    ChildUser user(23.34);
    user.print();
}
int main13()
{
   // test1();
   //test2();
   //test3();
    return 0;
}

